#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

FSM=
NSTATES=
NLTL=
LTLPRIORITIES=

while getopts ':a:n:f:u:' opt ; do
    case "$opt" in
        a) FSM="$OPTARG" ;;
        n) NSTATES="$OPTARG" ;;
        f) NLTL="$OPTARG" ;;
        u) LTLPRIORITIES="$OPTARG" ;;
        [?]) echo >&2 "Usage: $0 -a (EFSM file) -n (number of EFSM states) -f (number of LTL formulae) -u (LTL priorities in the randltl format)" && exit 1 ;;
    esac
done

if [[ -z $FSM || -z $NSTATES || -z $NLTL ]] 
then
   echo >&2 "Usage: $0 -a (EFSM file) -n (number of EFSM states) -f (number of LTL formulae)" && exit 1
fi


cwd=$(pwd)


$SCRIPT_DIR/genltl -a $FSM -n $NLTL -u "$LTLPRIORITIES" | sed 's/&&/and/g' | $SCRIPT_DIR/spin2egorov | sed -r 's/^\((.+)\)$/\1/g' | grep -v -P '^!.+' | grep -v -P '^wasEvent\(.+\)$' | grep -v -P '^wasAction\(.+\)$' | grep -v -P '^true$' | grep -v -P '^false$'> formulas
$SCRIPT_DIR/select-formulas -a $FSM -n $NSTATES -f $cwd/formulas
